package com.googlecode.jawb;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import com.googlecode.jawb.AnnotationParser.RTFieldBean;

public class JAWB {
	/**
	 * Loads data from stream and maps them to defined class.
	 * 
	 * @param inputStream
	 *            Stream from which bytes will be loaded.
	 * @param toClass
	 *            Class to which data should be mapped.
	 * @return Instance of a requested class with mapped data.
	 * @throws IOException
	 *             I/O error.
	 */
	public Object loadFrom(InputStream inputStream, Class<?> toClass, RTFieldBean... injectedValues) throws IOException {
		InputProcessor inputProcessor = new InputProcessor(inputStream, toClass, this, injectedValues);
		inputProcessor.process();

		return inputProcessor.getResult();
	}
	
	/**
	 * Saves object as a stream.
	 * 
	 * @param outputStream
	 *            Stream to save the object to.
	 * @param whichObject
	 *            Object which should be saved.
	 * @throws IOException
	 *             I/O error.
	 */
	public void saveTo(OutputStream outputStream, Object whichObject) throws IOException {
		OutputProcessor outputProcessor = new OutputProcessor(outputStream, whichObject, this);
		outputProcessor.process();
		outputProcessor.check();
	}
}
